﻿var _IsEditing;
var _application, _functioncode;

function window.onload() {
    _IsEditing = false;
    var app = document.getElementById("__application");
    if (app) {
        var appcode = app.value;
        var listCtl = document.getElementById("appQueryCtl0");
        for (var i = 0, ic = listCtl.options.length; i < ic; i++) {
            if (listCtl.options[i].value == appcode) { listCtl.options[i].selected = true; showFunctionTree(); break }
        }
    }
}

//显示帮助文档列表
function showFileHelp(application, functioncode) {
    _application = application;
    _functioncode = functioncode;

    _IsEditing = false;
    reDisplay("m_Edit,m_More");
    deDisplay("m_New,m_Del,m_Save,m_Cancle");

    var sFilter = "Application='" + _application + "' AND FunctionCode='" + _functioncode + "'";
    /*    
    if (_IsEditing)
    {
    if (confirm("正在编辑数据，是否保存？"))
    {
    save(sFilter)
    }
    else { cancle(sFilter) }
    }
    else   
    */

    if (_functioncode.length == 6) {
        deDisplay("m_Edit,m_More");
    }
    else {
        reDisplay("m_Edit,m_More");
    }
    
    AppGridE1.Refresh(sFilter);
}

//显示功能树
function showFunctionTree() {
    var listCtl = document.getElementById("appQueryCtl0");
    var strcode = listCtl.options[listCtl.selectedIndex].value;
    frmTree.location = "Function_Filehelp_Tree.aspx?application=" + strcode;
}

//增加行
function addRow() {
    AppGridE1.AddRow([_application, _functioncode], ["", "", ""]);
}

//删除行
function delRow() {
    AppGridE1.DelRow(true);
}

//进入编辑状态
function edit() {
    AppGridE1.SetReadonly("filedescript", false);
    AppGridE1.SetReadonly("filepath", false);
    AppGridE1.SetReadonly("helppath", false);
    deDisplay("m_Edit,m_More");
    reDisplay("m_New,m_Del,m_Save,m_Cancle");
    _IsEditing = true;
}


//在编辑状态下取消编辑
function cancle(sFilter) {
    reDisplay("m_Edit,m_More");
    deDisplay("m_New,m_Del,m_Save,m_Cancle");
    _IsEditing = false;
    AppGridE1.Refresh(sFilter);
}

//在编辑状态下保存数据
function save(sFilter) {
    var sRtn = XmlHttpRequest("/Map.Ext/MyFileHelp.aspx", "SaveDate", "", AppGridE1.GetXml());
    if (sRtn) {
        var obj = eval('(' + sRtn + ')');
        if (!obj) {
            alert("保存数据时发生错误，请与管理员联系！");
            AppGridE1.event.returnValue = false;
        }
        else if (obj.result) {
            //操作成功
            alert("保存成功！");
        }
        else {
            //操作失败
            if (obj.returnValue) {
                var msg = obj.message + "\n" + obj.returnValue.join("\n")
                alert(msg);
            }
            else alert(obj.message);
            AppGridE1.event.returnValue = false;
        }
    }
    cancle(sFilter);
}

//导出Excel
function exportExcel() {
    var sApp = _application;
    if (confirm("导出全部系统的数据吗？")) sApp = "";
    var sRtn = XmlHttpRequest("/Security/Security_XmlHTTP.aspx", "ExportExcel", "application=" + sApp);
    if (sRtn) {
        var obj = eval('(' + sRtn + ')');
        if (!obj) {
            alert("导出数据时发生错误，请与管理员联系！");
            return false;
        }
        else if (obj.result) {
            //操作成功
            window.open(obj.returnValue, "_self");
        }
        else {
            //操作失败
            alert(obj.message);
            return false;
        }
    }
}

//导入Excel
function importExcel() {
    openMyWin("Function_Filehelp_Import.aspx?application=" + _application + "&functionCode=" + _functioncode + "", "导入Excel", 400, 200);
}